import { Component, Vue } from 'vue-property-decorator';
@Component({
})
export class mixinTime extends Vue {
    setTime(picker: any, days: any) {
        const end = new Date();
        const start = new Date();
        start.setTime(start.getTime() - 3600 * 1000 * 24 * days);
        picker.$emit("pick", [start, end]);
    }

    timeOptionRange: any = null;
    getPickerOptions() {
        return {
            onPick: (time: any) => {
                // 当第一时间选中才设置禁用
                if (time.minDate && !time.maxDate) {
                    this.timeOptionRange = time.minDate;
                }
                if (time.maxDate) {
                    this.timeOptionRange = null;
                }
            },
            disabledDate: (time: any) => {
                const timeOptionRange: any = this.timeOptionRange;
                const secondNum = 60 * 60 * 24 * 6 * 1000;
                if (timeOptionRange) {
                    return (
                        time.getTime() >
                        timeOptionRange.getTime() + secondNum ||
                        time.getTime() <
                        timeOptionRange.getTime() - secondNum
                    );
                }
            }
        }
    }
    pickerOptions: any = {
        shortcuts: [
            {
                text: "最近一年",
                onClick: (picker: any) => {
                    const start = new Date();
                    start.setTime(start.getTime() + 3600 * 1000 * 24 * 365);
                    picker.$emit("pick", start);
                }
            }
        ],
        disabledDate: (time: any) => {
            return time.getTime() <
                new Date().getTime()
        }
    }
}
